home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / NSIS 2.41 / nsis-2.41-setup.exe / Include / WinVer.nsh < prev    next >
Encoding:
Text File  |  2008-09-14  |  6.4 KB  |  233 lines

  1. ; ---------------------
  2. ;      WinVer.nsh
  3. ; ---------------------
  4. ;
  5. ; LogicLib extensions for handling Windows versions and service packs.
  6. ;
  7. ; IsNT checks if the installer is running on Windows NT family (NT4, 2000, XP, etc.)
  8. ;
  9. ;   ${If} ${IsNT}
  10. ;     DetailPrint "Running on NT. Installing Unicode enabled application."
  11. ;   ${Else}
  12. ;     DetailPrint "Not running on NT. Installing ANSI application."
  13. ;   ${EndIf}
  14. ;
  15. ; AtLeastWin<version> checks if the installer is running on Windows version at least as specified.
  16. ; IsWin<version> checks if the installer is running on Windows version exactly as specified.
  17. ; AtMostWin<version> checks if the installer is running on Windows version at most as specified.
  18. ;
  19. ; <version> can be replaced with the following values:
  20. ;
  21. ;   95
  22. ;   98
  23. ;   ME
  24. ;
  25. ;   NT4
  26. ;   2000
  27. ;   XP
  28. ;   2003
  29. ;   Vista
  30. ;
  31. ; AtLeastServicePack checks if the installer is running on Windows service pack version at least as specified.
  32. ; IsServicePack checks if the installer is running on Windows service pack version exactly as specified.
  33. ; AtMostServicePack checks if the installer is running on Windows service version pack at most as specified.
  34. ;
  35. ; Usage examples:
  36. ;
  37. ;   ${If} ${IsNT}
  38. ;   DetailPrint "Running on NT family."
  39. ;   DetailPrint "Surely not running on 95, 98 or ME."
  40. ;   ${AndIf} ${AtLeastWinNT4}
  41. ;     DetailPrint "Running on NT4 or better. Could even be 2003."
  42. ;   ${EndIf}
  43. ;
  44. ;   ${If} ${AtLeastWinXP}
  45. ;     DetailPrint "Running on XP or better."
  46. ;   ${EndIf}
  47. ;
  48. ;   ${If} ${IsWin2000}
  49. ;     DetailPrint "Running on 2000."
  50. ;   ${EndIf}
  51. ;
  52. ;   ${If} ${IsWin2000}
  53. ;   ${AndIf} ${AtLeastServicePack} 3
  54. ;   ${OrIf} ${AtLeastWinXP}
  55. ;     DetailPrint "Running Win2000 SP3 or above"
  56. ;   ${EndIf}
  57. ;
  58. ;   ${If} ${AtMostWinXP}
  59. ;     DetailPrint "Running on XP or older. Surely not running on Vista. Maybe 98, or even 95."
  60. ;   ${EndIf}
  61. ;
  62. ; Warning:
  63. ;
  64. ;   Windows 95 and NT both use the same version number. To avoid getting NT4 misidentified
  65. ;   as Windows 95 and vice-versa or 98 as a version higher than NT4, always use IsNT to
  66. ;   check if running on the NT family.
  67. ;
  68. ;     ${If} ${AtLeastWin95}
  69. ;     ${And} ${AtMostWinME}
  70. ;       DetailPrint "Running 95, 98 or ME."
  71. ;       DetailPrint "Actually, maybe it's NT4?"
  72. ;       ${If} ${IsNT}
  73. ;         DetailPrint "Yes, it's NT4! oops..."
  74. ;       ${Else}
  75. ;         DetailPrint "Nope, not NT4. phew..."
  76. ;       ${EndIf}
  77. ;     ${EndIf}
  78.  
  79. !verbose push
  80. !verbose 3
  81.  
  82. !ifndef ___WINVER__NSH___
  83. !define ___WINVER__NSH___
  84.  
  85. !include LogicLib.nsh
  86.  
  87. !define WINVER_95 0x400
  88. !define WINVER_98 0x40A ;4.10
  89. !define WINVER_ME 0x45A ;4.90
  90.  
  91. !define WINVER_NT4 0x400
  92. !define WINVER_2000 0x500
  93. !define WINVER_XP 0x501
  94. !define WINVER_2003 0x502
  95. !define WINVER_VISTA 0x600
  96.  
  97. !macro __GetWinVer
  98.   !insertmacro _LOGICLIB_TEMP
  99.   System::Call kernel32::GetVersion()i.s
  100.   Pop $_LOGICLIB_TEMP
  101. !macroend
  102.  
  103. !macro __ParseWinVer
  104.   !insertmacro __GetWinVer
  105.   Push $0
  106.   IntOp $0 $_LOGICLIB_TEMP & 0xff
  107.   IntOp $0 $0 << 8
  108.   IntOp $_LOGICLIB_TEMP $_LOGICLIB_TEMP & 0xff00
  109.   IntOp $_LOGICLIB_TEMP $_LOGICLIB_TEMP >> 8
  110.   IntOp $_LOGICLIB_TEMP $_LOGICLIB_TEMP | $0
  111.   Pop $0
  112. !macroend
  113.  
  114. !macro _IsNT _a _b _t _f
  115.   !insertmacro __GetWinVer
  116.   IntOp $_LOGICLIB_TEMP $_LOGICLIB_TEMP & 0x80000000
  117.   !insertmacro _== $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  118. !macroend
  119. !define IsNT `"" IsNT ""`
  120.  
  121. !macro __WinVer_DefineOSTest Test OS
  122.  
  123.   !define ${Test}Win${OS} `"" WinVer${Test} ${WINVER_${OS}}`
  124.  
  125. !macroend
  126.  
  127. !macro __WinVer_DefineOSTests Test
  128.  
  129.   !insertmacro __WinVer_DefineOSTest ${Test} 95
  130.   !insertmacro __WinVer_DefineOSTest ${Test} 98
  131.   !insertmacro __WinVer_DefineOSTest ${Test} ME
  132.   !insertmacro __WinVer_DefineOSTest ${Test} NT4
  133.   !insertmacro __WinVer_DefineOSTest ${Test} 2000
  134.   !insertmacro __WinVer_DefineOSTest ${Test} XP
  135.   !insertmacro __WinVer_DefineOSTest ${Test} 2003
  136.   !insertmacro __WinVer_DefineOSTest ${Test} VISTA
  137.  
  138. !macroend
  139.  
  140. !macro _WinVerAtLeast _a _b _t _f
  141.   !insertmacro __ParseWinVer
  142.   !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  143. !macroend
  144.  
  145. !macro _WinVerIs _a _b _t _f
  146.   !insertmacro __ParseWinVer
  147.   !insertmacro _= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  148. !macroend
  149.  
  150. !macro _WinVerAtMost _a _b _t _f
  151.   !insertmacro __ParseWinVer
  152.   !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  153. !macroend
  154.  
  155. !insertmacro __WinVer_DefineOSTests AtLeast
  156. !insertmacro __WinVer_DefineOSTests Is
  157. !insertmacro __WinVer_DefineOSTests AtMost
  158.  
  159.  
  160. !macro __GetWinServicePack
  161.   !insertmacro _LOGICLIB_TEMP
  162.  
  163.   Push $0
  164.   Push $1
  165.   Push $2
  166.  
  167.   StrCpy $2 0
  168.  
  169.   ; $1 = malloc(sizeof(OSVERSIONINFOEXA))
  170.   System::Alloc 156
  171.   Pop $1
  172.   StrCmp $1 0 Label_WinVer_ServicePack_End_${LOGICLIB_COUNTER}
  173.     ; ($1)->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA)
  174.     System::Call /NOUNLOAD '*$1(&i4 156)'
  175.     ; GetVersionEx($1)
  176.     System::Call /NOUNLOAD 'kernel32::GetVersionEx(i r1) i.r0'
  177.     StrCmp $0 0 Label_WinVer_ServicePack_GetVersion_${LOGICLIB_COUNTER}
  178.       ; $2 = ($1)->wServicePackMajor
  179.       System::Call /NOUNLOAD '*$1(&t148, &i2.r2)'
  180.       Goto Label_WinVer_ServicePack_End_${LOGICLIB_COUNTER}
  181.  
  182. Label_WinVer_ServicePack_GetVersion_${LOGICLIB_COUNTER}:
  183.       ; ($1)->dwOSVersionInfoSize = sizeof(OSVERSIONINFOA)
  184.       System::Call /NOUNLOAD '*$1(&i4 148)'
  185.       ; GetVersionEx($1)
  186.       System::Call /NOUNLOAD 'kernel32::GetVersionEx(i r1) i.r0'
  187.       StrCmp $0 0 Label_WinVer_ServicePack_End_${LOGICLIB_COUNTER}
  188.         ; $2 = ($1)->szCSDVersion
  189.         System::Call /NOUNLOAD '*$1(&t20, &t128.r2)'
  190.         StrCpy $0 $2 13
  191.         StrCmp $0 "Service Pack " 0 +3
  192.           StrCpy $2 $2 "" 13
  193.           Goto +2
  194.         StrCpy $2 0
  195.  
  196. Label_WinVer_ServicePack_End_${LOGICLIB_COUNTER}:
  197.     ; free($1)
  198.     StrCmp $1 0 +2
  199.       System::Free $1
  200.  
  201.   StrCpy $_LOGICLIB_TEMP $2
  202.  
  203.   Pop $2
  204.   Pop $1
  205.   Pop $0
  206.  
  207.   !insertmacro _IncreaseCounter
  208.  
  209. !macroend
  210.  
  211. !define AtLeastServicePack `"" AtLeastServicePack`
  212. !macro _AtLeastServicePack _a _b _t _f
  213.   !insertmacro __GetWinServicePack
  214.   !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  215. !macroend
  216.  
  217. !define AtMostServicePack `"" AtMostServicePack`
  218. !macro _AtMostServicePack _a _b _t _f
  219.   !insertmacro __GetWinServicePack
  220.   !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  221. !macroend
  222.  
  223. !define IsServicePack `"" IsServicePack`
  224. !macro _IsServicePack _a _b _t _f
  225.   !insertmacro __GetWinServicePack
  226.   !insertmacro _= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  227. !macroend
  228.  
  229.  
  230. !endif # !___WINVER__NSH___
  231.  
  232. !verbose pop
  233.